package com.example.iterator;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * Created by Risky57 on 2017/4/28.
 */

public class Students implements Iterable{
    private List<String> names;

    public Students () {
        names = new LinkedList<>();
        names.add("孟宪义");
        names.add("肖玲玲");
        names.add("武奇");
        names.add("陈丰尧");
        names.add("吴比航");
    }

    @Override
    public Iterator iterator () {
        return new ListIterator();
    }

    private class ListIterator implements Iterator{

        private int index;
        @Override
        public boolean hasNext () {
            if (index < names.size()) return true;
            return false;
        }

        @Override
        public String next () {

            if (hasNext()){
                return names.get(index++);
            }

            return null;
        }
    }
}
